package com.system.uitls;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.JdbcOperations;

public class IdUtils {
	public static synchronized String getSequence(JdbcOperations jdbc, final String sequenceName) {
		return (String) jdbc.execute(new ConnectionCallback() {
			public Object doInConnection(Connection conn) throws SQLException,DataAccessException {
				CallableStatement cstmt = conn.prepareCall("{? = call GetNextId(?)}");
				cstmt.setString(2, sequenceName);
				cstmt.registerOutParameter(1, 12);
				cstmt.execute();
				return cstmt.getString(1);
			}
		});
	}
}